import {BaseCrudApi} from "~/api/util/BaseService";
import {Menu} from "@/api/system/menu/types";
import {reactive} from "vue";

export class MenuApi extends BaseCrudApi<Menu> {

    baseUrl: string = "/system/menu";

    treeState = reactive<{
        loading: boolean,
        data: Menu[],
        checkStrictly: boolean
    }>({
        loading: false,
        data: [],
        checkStrictly: false,
    });

    tree() {
        return new Promise((resolve, reject) => {
            this.treeState.loading = true;
            this.get<Menu[]>("/tree").then(res => {
                if (res.data) {
                    this.treeState.data = res.data;
                }
                this.treeState.loading = false;
                resolve(res);
            });
        });
    }

}
